import java.util.Scanner;

public class MainD {
    public static void main(String[] args) {

        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int m = in.nextInt();
        int a[][] = new int[n][n];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                a[i][j] = in.nextInt();
            }
        }
        if(m==1) {
            System.out.println(1);
            return;
        }
        if (m==2){
            System.out.println(2);
            return;
        }
        int pp = 1;
        int p = 2;
        int cur = 3;
        for (int i = 3; i <= m; i++) {
            cur = a[p-1][pp-1];
            pp = p;
            p = cur;
        }
        System.out.println(cur);
    }
}
